package com.bytedance.common.base

import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import com.alibaba.android.arouter.facade.Postcard
import com.alibaba.android.arouter.launcher.ARouter

/**
 * Created by chenxiong
 * date 11/22/21
 */
abstract class BaseActivity: AppCompatActivity() {

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(getLayoutId())
        initData()
        initListener()
    }
    //设置布局ID
    abstract fun getLayoutId(): Int

    //初始化数据
    abstract fun initData()

    //设置事件监听
    abstract fun initListener()

    fun open(path: String, build: Postcard.() -> Unit = {}) {
        val postcard = ARouter.getInstance().build(path)
        postcard.build()
        postcard.navigation()
    }

    fun openWithFinish(path: String, build: Postcard.() -> Unit = {}) {
        open(path, build)
        finish()
    }
}